#include<bits/stdc++.h>
using namespace std;
#define N 1145141
struct tree{
	int l,r,ans,L,R;
}t[N*4];
tree operator +(const tree &x,const tree &y)
{
	return {x.l,y.r,min(min(x.ans,y.ans),y.R-x.L),max(x.L,y.L),min(x.R,y.R)};
}
#define ls (o<<1)
#define rs ((o<<1)^1)
#define mid (t[o].l+t[o].r>>1)
#define inf 10000000
void build(int l,int r,int o)
{
	t[o]={l,r,inf,-inf,inf};
	if(l==r) return;
	build(l,mid,ls);build(mid+1,r,rs);
}
void change(int x,int ty,int v,int o)
{
	if(t[o].l==t[o].r)
	{
		ty?t[o].L=v:t[o].R=v;
		t[o].ans=t[o].R-t[o].L;
		return;
	}
	if(x<=mid) change(x,ty,v,ls);
	if(x>mid) change(x,ty,v,rs);
	t[o]=t[ls]+t[rs];
}
#undef rs
#undef ls
int Q;
int l,r,c0;
char op;
multiset<int> rs[N],ls[N];
int main()
{
	freopen("stone.in","r",stdin);
	freopen("stone.out","w",stdout);
	cin>>Q;
	build(1,1000000,1);
	while(Q--)
	{
		cin>>op>>l>>r;
		if(l!=r)
		{
			if(op=='A')
			{
				rs[l].insert(r);
				ls[r].insert(l);
			}
			else
			{
				rs[l].erase(rs[l].lower_bound(r));
				ls[r].erase(ls[r].lower_bound(l));
			}
			change(l,0,(rs[l].empty()?inf:int(*rs[l].begin())),1);
			change(r,1,(ls[r].empty()?-inf:int(*ls[r].rbegin())),1);
		}
		else op=='A'?c0++:c0--;
		if(c0)
		{
			cout<<"0\n";continue;
		}
		if(t[1].R>t[1].L)
			cout<<*rs[t[1].L].begin()-*ls[t[1].R].rbegin()<<"\n";
		else cout<<t[1].ans<<"\n";
	}
}
